package com.javacoo.xservice.base.support.log;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

import com.javacoo.xservice.base.support.event.TransCompleteEvent;
import com.javacoo.xservice.base.support.log.config.LogConfig;

import lombok.extern.slf4j.Slf4j;

/**
 * 交易完成事件处理：记录日志
 * <p>说明:</p>
 * <li>交易完成事件:TransCompleteEvent,为异步事件</li>
 * @author DuanYong
 * @since 2017年7月3日上午10:05:53
 */
@Slf4j
@Component
@ConditionalOnBean(LogConfig.class)
public class LogTransCompleteEventHandler implements ApplicationListener<TransCompleteEvent> {
    @Autowired
    private LogService logService;
    @Autowired
    private LogConfig appLogSetting;
	@Override  
    public void onApplicationEvent(TransCompleteEvent event) {
		if(appLogSetting.getRecord()){
            logService.record(event.getSwapAreaData());
		}
    }
}
